<!--#
layout("/layouts/store.html"){
#-->
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/store/cms/channel/add" data-pjax><i class="ti-plus"></i>${msg['cms.channel.column.newcolumn']}</a>
    </div>
    <div class="pull-right">
        <div class="btn-group tool-button">
            <a class="btn btn-primary navbar-btn" href="${base}/store/cms/channel/sort" data-pjax><i class="ti-share"></i> ${msg['cms.channel.column.columnsort']}</a>
        </div>
    </div>
</header>
<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <div class="row mb15 mt10">
            <div class="col-lg-12">
                <table id="treeTable" class="table no-m">
                    <thead>
                    <tr>
                        <th class="col-md-2 pd-l-lg">
                            <span class="pd-l-sm ml20"></span>${msg['cms.channel.column.name']}
                        </th>
                        <th class="col-md-1">${msg['cms.channel.column.type']}</th>
                        <th class="col-md-1">${msg['cms.channel.column.url']}</th>
                        <th class="col-md-1">${msg['cms.channel.column.opentheway']}</th>
                        <th class="col-md-1">${msg['cms.channel.column.enablestatus']}</th>
                        <th class="col-md-2">${msg['cms.channel.column.operation']}</th>
                    </tr>
                    </thead>
                    <tbody>
                    <!--# for(obj in list){
                    #-->
                    <tr data-tt-id="${obj.id!}" data-tt-parent-id="${obj.parentId!}" data-tt-branch="${obj.hasChildren!}">
                        <td>
                            <span class="pd-l-sm"></span> ${obj.name!}
                        </td>
                        <td><!--#if(obj.type=="article"){#-->${msg['cms.channel.column.article']}<!--#}#--><!--#if(obj.type=="photo"){#-->${msg['cms.channel.column.photo']}<!--#}#--></td>
                        <td>${obj.url!}</td>
                        <td>${obj.target!}</td>
                        <td><!--#if(false==obj.disabled){#--><i id="disable_${obj.id!}" class="fa fa-circle text-success ml5"></i><!--#}else{#--><i id="disable_${obj.id!}" class="fa fa-circle text-danger ml5"></i><!--#}#--></td>
                        <td>
                            <div class="btn-group">
                                <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
                                    <i class="ti-settings"></i>
                                    <span class="ti-angle-down"></span>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                    <li><a href="${base}/store/cms/channel/edit/${obj.id!}" data-pjax>${msg['cms.channel.column.edit']}</a></li>
                                    <li><a href="javascript:;" onclick="del('${obj.id!}')">${msg['cms.channel.column.delete']}</a></li>
                                    <!--<li><a href="${base}/store/cms/channel/add/${obj.id}" data-pjax>${msg['cms.channel.column.addchildcolumn']}</a></li>-->
                                    <li class="divider"></li>
                                    <li><a href="javascript:;" onclick="enableRole('${obj.id!}')">${msg['cms.channel.column.enable']}</a></li>
                                    <li><a href="javascript:;" onclick="disableRole('${obj.id!}')">${msg['cms.channel.column.disable']}</a></li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                    <!--#
                    } #-->
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<a class="exit-offscreen"></a>
<!-- 排序 -->
<div id="dialogSort" class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

        </div>
    </div>
</div>
<!-- 删除 -->
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">${msg['cms.channel.column.deletemenu']}</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">${msg['cms.channel.column.text']}
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">${msg['cms.channel.column.cancel']}</button>
                <button id="ok" type="button" class="btn btn-primary" data-loading-text="${msg['cms.channel.column.nowdelete']}">${msg['cms.channel.column.soure']}</button>
            </div>
        </div>
    </div>
</div>
<!-- 详情 -->
<div id="dialogDetail" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

        </div>
    </div>
</div>
<script>
    var treeTable;
    $(function () {
        $("#dialogDetail").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
        });
        $("#dialogSort").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
        });
        treeTable= $("#treeTable").treetable({
            expandable: true,
            onNodeExpand : function(){
                var node = this;
                var rows = "<tr data-tt-id=\"loading\" data-tt-parent-id=\""+node.id+"\" data-tt-branch=\"false\"><td colspan='5'><img src=\""+base+"/assets/img/loading.gif\"/>loading</td></tr>";
                treeTable.treetable("loadBranch", node, rows);
                $.post("${base}/store/cms/channel/child/"+node.id,{}, function(data){
                    treeTable.treetable("unloadBranch", node);
                    treeTable.treetable("loadBranch", node, data);
                });
            }
        });
    });
    function enableRole(id) {
        $.post("${base}/store/cms/channel/enable/" + id, {}, function (data) {
            if (data.code == 0) {
                $("#disable_" + id).attr("class", "fa fa-circle text-success ml5");
            } else {
                Toast.error(data.msg);
            }
        }, "json");
    }
    function disableRole(id) {
        $.post("${base}/store/cms/channel/disable/" + id, {}, function (data) {
            if (data.code == 0) {
                $("#disable_" + id).attr("class", "fa fa-circle text-danger ml5");
            } else {
                Toast.error(data.msg);
            }
        }, "json");
    }
    function del(id){
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#ok").unbind("click");
        dialog.find("#ok").bind("click", function(event){
            var btn = $(this);
            btn.button("loading");
            $.post("${base}/store/cms/channel/delete/"+id,{},function(data){
                //重置按钮状态，关闭提示框
                dialog.modal("hide");
                if(data.code==0){
                    Toast.success(data.msg);
                    treeTable.treetable("removeNode", id);
                    //从表格中移除此行
                }else{
                    Toast.error(data.msg);
                }
                btn.button("reset");
            },"json");
        });
    }
</script>

<!--#}#-->